package com.boang.string;

/*
  @author: 13813
  @date: 2024/11/21 11:03
*/
public class StringDemo {
    /*
       1.字符串是常量；它们的值在创建之后不能更改
       2.字节数组 private final byte[] value;
     */
    public static void main(String[] args) {
//        m1();
//        m2();
//        m3();
//        m4();
        String s1 = new String("A");
        String s2 = "A";
        System.out.println(s1 == s2); //false

        //创建了几个对象：2个，new String，"A"
    }

    private static void m4() {
        String s1 = "A";
        s1 = "B";
    }

    private static void m3() {
        //字符串常量池：没有创建，放入常量池，有内容相同的对象则直接使用
        String s1 = "A";
        String s2 = "A";
        System.out.println(s1 == s2);
    }

    private static void m2() {
        //字面量
        String s1 = "A";
        String s2 = "B";
        System.out.println(s1 == s2);
        //几个String类对象: 个
    }

    private static void m1() {
        String s1 = new String();
        String s2 = "";

        System.out.println(s1 == s2);
        System.out.println(s1.equals(s2));
    }
}
